package hu.uniobuda.nik.openday;

import hu.uniobuda.nik.openday.utils.Config;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.text.method.MovementMethod;
import android.view.MotionEvent;
import android.widget.TextView;

public class CustomLinkMovementMethod extends LinkMovementMethod {

	private boolean moving = false;

	@Override
	public boolean onTouchEvent(TextView widget, Spannable buffer,
			MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_MOVE)
			moving = true;
		if (!super.onTouchEvent(widget, buffer, event)) {
			if (event.getAction() == MotionEvent.ACTION_UP && !moving) {
				if ((Boolean) widget.getTag()) {
					widget.setMaxLines(Integer.MAX_VALUE);
					widget.setTag(false);
				} else {
					widget.setMaxLines(Config.MAX_LINES);
					widget.setTag(true);
				}
				
			}
		}
		moving = false;
		return true;
	}

	public static MovementMethod getInstance() {
		if (sInstance == null)
			sInstance = new CustomLinkMovementMethod();

		return sInstance;
	}

	private static CustomLinkMovementMethod sInstance;
}
